home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / wtek0693.zip / OOPALLEY.ZIP / RANGE.H < prev    next >
C/C++ Source or Header  |  1993-04-27  |  2KB  |  47 lines

  1. #ifndef RANGE_H
  2. #define RANGE_H
  3.  
  4. #include "object.h"
  5.  
  6. extern const Class class_Range;
  7.  
  8. ////////////////////////////////////////////////////////////
  9. // class Range (declaration)
  10. ////////////////////////////////////////////////////////////
  11. class Range: public Object {
  12.     int first,len;
  13. public:
  14.                 // constructors, destructors
  15.                 Range()                 { first = 0; len = -1; }
  16.                 Range(int f, int l)     { first = f; len = l; }
  17.                 Range(const Range& r)   { first = r.first;  len = r.len; }
  18.  
  19.                 // operators
  20.     void        operator=(const Range& r)  { first = r.first;  len = r.len; }
  21.     bool        operator==(const Range& r) const
  22.                 {
  23.                     return ((first == r.first) && (len == r.len));
  24.                 }
  25.     bool        operator!=(const Range& r) const
  26.                 {
  27.                     return !(*this==r);
  28.                 }
  29.  
  30.     int                     length() const      { return len; }
  31.     int                     length(int l)       { return len = l; }
  32.     int                     firstIndex() const  { return first; }
  33.     int                     firstIndex(int f)   { return first = f; }
  34.     int                     lastIndex() const   { return (first + len - 1); }
  35.     int                     lastIndex(int i)    { len = i - first + 1;  return i; }
  36.     bool                    valid() const       { return (len >= 0); }
  37.     virtual Object*         copy() const;       // return shallowCopy();
  38.     virtual void            deepenShallowCopy();   
  39.     virtual unsigned        hash() const;
  40.     virtual const Class*    isA() const;
  41.     virtual bool            isEqual(const Object&) const;
  42.     virtual void            printOn(ostream& strm) const;
  43.     virtual const Class*    species() const;
  44. };
  45.  
  46. #endif
  47.